#ifndef CLogOper_H
#define CLogOper_H
/********************************************************************************
** @ Date:2024/04/09
** @ Author: HanJiaXin
** @ Description:日志单例类
** @ Version:1.0.0
** @ ClassName:CLogOper
** @ Fun:
********************************************************************************/
#include <QDateTime>
#include <QMap>
#include "LogModule.h"

enum ELogType
{
    enWorkInfo = 1,//运行
    enNormal,//正常
    enAlarm,//报警
    enErr,//错误
    enDevAlarm,//硬件故障
};

struct SExecLog
{
    QDateTime      m_dLogTime;          //时间
    QString        m_sDevName;
    bool           m_bExecResult;       //操作执行结果  false 失败  true成功
    QString        m_sDescription;     //操作描述
    int            m_nAlarmLevel;       //报警等级 1运行 2正常 3报警 4错误 5硬件故障

    SExecLog()
    {
        m_sDevName = "";
        m_bExecResult = false;
        m_nAlarmLevel = -1;
        m_dLogTime = QDateTime::currentDateTime();
    }
};

class CLogOper
{
public:
    static CLogOper& instance()
    {
        static CLogOper instance;
        return instance;
    }
    LogModule* getLogModule();//根据场景Guid获取日志控件指针
    void setLogModule(LogModule* pModule);
    void addLogTab(const QString& sGuid, int& nTabNo);
    QTableView* getLogTab(const QString& sGuid);
    void returnTab(QTableView*);

    void addMsg(QString sGuid, SExecLog sExecLog);//添加日志

private:
    CLogOper();
    ~CLogOper();

    QMap<QString, int>  m_mapLogTab;            //key:guid value:tab编号
    LogModule*          m_pLogModule;           //日志控件
};
#endif
